#include <iostream>
#define N 14
using namespace std;

int p, q;
int st[N+1][N+1];
int dx[8] = { -2,-2,-1,-1,1,1,2,2 };
int dy[8] = { -1,1,-2,2,-2,2,-1,1 };

bool dfs(int x, int y, int cnt)
{
    st[x][y] = cnt;
    if (cnt == (N)*(N))
    {
        for(int i = 1;i<=N;i++)
        {
            for (int j = 1; j <= N; j++) {
                cout << st[i][j] << "\t";
            }
            cout << endl;
        }
        return true;
    }

    int probability[8] = {0};
    if (cnt != N * N - 1) {
        for (size_t i = 0; i < 8; i++)
        {
            int newX = x + dx[i]; int newY = y + dy[i];
            if (newX < 1 || newX>N || newY < 1 || newY>N) continue;
            if (st[newX][newY] > 0) continue;
            for (size_t j = 0; j < 8; j++)
            {
                int newX1 = newX + dx[j]; int newY1 = newY + dy[j];
                if (newX1 < 1 || newX1>N || newY1 < 1 || newY1>N) continue;
                if (st[newX1][newY1] > 0) continue;
                probability[i]++;
            }
        }
        for (size_t i = 1; i < 8; i++)
        {
            for (size_t j = 0; j < 8; j++)
            {
                if (probability[j] == i)
                {
                    if (dfs(x + dx[j], y + dy[j], cnt + 1))return true;
                }
            }
        }
    }
    else
    {
        for (size_t i = 0; i < 8; i++)
        {
            if (x + dx[i] < 1 || x + dx[i]>8 || y + dy[i] < 1 || y + dy[i]>8) continue;
            if (st[x + dx[i]][y + dy[i]]) continue;
            if (dfs(x + dx[i], y + dy[i], cnt + 1)) return true;
        }
    }
    st[x][y] = 0;
    return false;
}
int main()
{
    cin >> p >> q;
    dfs(p, q, 1);
    return 0;
}